<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>影视资源聚合搜索</title>
	<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /> 
	
	<!-- ZUI 标准版压缩后的 CSS 文件 -->
	<link rel="stylesheet" href="/css/zui.min.css">
	<link rel="stylesheet" href="/css/mzui.min.css">
	<link rel="stylesheet" href="/css/mobile.search.css">
</head>
<body>

<!-- 搜索框 -->
<div class="search">
    <img src="http://fs.yqfw.cdyoue.com/Fq4-RXDEd2Iu1_HdjcNt0kKYOf_s" />
    <input type="search" placeholder="搜索" id="search-input"/>
    <div class="delete"></div>
</div>
<!--
<div class="input-control search-box has-icon-left has-icon-right" id="searchbox" style="position: fixed;left: 0rem;top: 0rem;width: 100%;z-index: 1024;">
  <input id="inputSearchExample1" type="search" class="form-control search-input" placeholder="搜索" style="height: 2rem;">
  <label for="inputSearchExample1" class="input-control-icon-left search-icon" style="margin-top:auto;margin-bottom:auto;"><i class="icon icon-search"></i></label>
  <a href="#" class="input-control-icon-right search-clear-btn" style="margin-top:auto;margin-bottom:auto;"><i class="icon icon-remove"></i></a>
</div>
-->
<div class="list section load-indicator" id="video-list">
</div>
<div class="nores">暂无数据</div>

<!-- 搜索结果列表 
<div class="list section load-indicator" id="video-list" style="margin-top: 2.5rem; min-height: 10rem;">
	<img src="/img/there.png" width="100%" height="20rem" />
</div>
-->
</body>

<!-- ZUI Javascript 依赖 jQuery -->
<script type="text/javascript" src="/js/jquery.js"></script>
<!-- ZUI 标准版压缩后的 JavaScript 文件 -->
<script type="text/javascript" src="/js/zui.min.js"></script>
<script type="text/javascript" src="/js/mzui.min.js"></script>
<!-- Art-Template.js -->
<script type="text/javascript" src="/js/template-web.min.js"></script>


<!-- 搜索结果列表模板 -->
<script id="video-list-item" type="text/html">
{{each videoList video idx}}
<a class="item multi-lines" href='/video/play?vodId={{video.vodId}}&code={{video.vodPlayFrom}}' target='_self'>
	<div class="avatar circle {{video.fromColor}} outline">{{video.fromShort}}</div>
    <div class="content">
	  <div class="title">
		  <span>{{video.vodName}}</span>&nbsp;<small class="text-green">{{video.typeName}}</small>
	  </div>
      <div>
        <small class="muted">{{video.vodTime}}</small>
        <div class="pull-right label {{if video.finished}}green-pale{{else}}red-pale{{/if}} text-tint">{{video.vodRemarks}}</div>
      </div>
    </div>
  </a>
{{/each}}	
</script>

<script>

/** 网页加载完成 */
$(function(){
	
});

$('#search-input').bind('keypress',function(event){
     if(event.keyCode == "13"){
    	 var wd = $(this).val();
    	 searchVideo(wd);
     }
 });

// 创建 display 实例
var myDisplay = new $.Display({
  display: 'messager'
});


// 搜索方法
function searchVideo(wd){
	
	// 置空
	//$('#video-list').html('');
	
	// 显示加载
	$('.list').empty()
	$('.nores').hide();
	$('#video-list').toggleClass('loading');
	
	if(!wd){
		location.href = "/";
	}
	
	$.ajax({
		type: "GET",
        url: "/video/list?wd=" + wd,
        dataType: "json",
        success: function(data){
			
		   if(data == null || data.length == 0){
			   var emptyHtml = '<img src="/img/empty.jpg" width="100%" height="100%" class="img-rounded" style="margin-top: 0.5rem;"/>'
			   $('#video-list').html(emptyHtml);
		   } else {
			   let result = template('video-list-item',{'videoList' : data});  //===注意点:  模板上得rows要跟template上得rows对应
           	   $('#video-list').html(result) //===直接赋值就可以实现了
		   }
		   
		   $('.nores').hide();
		   $("input").blur();
        },
        error: function(err){
			 // 调用 show() 方法显示
			myDisplay.show({
			  content: '服务开小差啦',
			  type: 'danger'
			});
			$('.nores').show();  
		},
		complete: function(){
			// 关闭加载中
			$('#video-list').toggleClass('loading');
		}
	});
}


 $("input").bind("input propertychange",function(event){
    var val = $("input").val()
     if(val != ''){
      $('.delete').show()
      for(let i of arr){ 
        if(i.indexOf(val) != -1){
 
          let result = replaceHandle(i,val)
          $('.list').append('<div class="items">'+result+'</div>')
          if($('.items').length != 0){
            $('.nores').hide()
          }else {
            $('.nores').show()
          }
        }else {
           
        }
      }
     }else{
      $('.delete').hide()
      //$('.nores').show()
     }
});

$('.delete').on('click',function(){
  $("input").val('')
  $('.delete').hide()
  $('.list').empty()
  $('.nores').show()
  $("input").focus();
})
 
function replaceHandle(parentStr,searchText){
  var res = new RegExp("("+searchText+")",'g');
  parentStr = parentStr.replace(res,"<span style='color:#44A8F8;'>" + searchText+"</span>");
  return parentStr;
}

</script>